package com.lams.action.comp;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.lams.action.SubAction;
import com.lams.jdbc.QueryUtils;
import com.lams.util.ResultEntity;
import com.lams.util.ViewParamsUtil;
import com.opensymphony.xwork2.ActionContext;

public class QueryAction extends SubAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = -7604082967251497883L;
	private String sqlCode;
	private String query;
	private String SCHOOL_ID;
	
	public String getSCHOOL_ID() {
		return SCHOOL_ID;
	}

	public void setSCHOOL_ID(String sCHOOL_ID) {
		SCHOOL_ID = sCHOOL_ID==null?"-1":sCHOOL_ID;
	}

	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}

	public String getSqlCode() {
		return sqlCode;
	}

	public void setSqlCode(String sqlCode) {
		this.sqlCode = sqlCode;
	}
	
	public String query(){
		Map params = ActionContext.getContext().getParameters();
		if(SCHOOL_ID==null || "".equals(SCHOOL_ID))
			this.setSCHOOL_ID(this.getQuery());
		params.put("SCHOOL_ID", this.getSCHOOL_ID());
		String sql = QueryUtils.getSqlBySqlCode(sqlCode, params);
		List<Map> data = QueryUtils.executeQuery(sql);
		ResultEntity result = new ResultEntity();
		result.setData(data);
		result.setTotalCount(data.size());
		result.setSuccess(true);
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
	}

	public String queryByCodeCate() {
		//final String CODE_CATE = "codecate";
		//String codeCate = ViewParamsUtil.getParam(CODE_CATE);
		Map params = ActionContext.getContext().getParameters();
		String sql = QueryUtils.getSqlBySqlCode("QUERYSCODECOMBO", params);
		//String qrySql = "select c.code as value , c.name from s_code c where c.code_cate = '" + codeCate + "'";
		List list = QueryUtils.executeQuery(sql);
		ResultEntity result = new ResultEntity();
		result.setTotalCount(list.size());
		result.setSuccess(true);
		result.setData(list);
		result.setLimit(this.getLimit());
		result.setStart(this.getStart());
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
		
	}
}
